package com.killif;

/**
 * 干掉if else
 * 1. int 赋值三目运算符
 * 2. string 赋值枚举
 * 3. 其他（例如输出一段日志）策略+工厂
 *
 * <p>
 * .
 *
 * @author 王志强
 * @date 2022-11-08
 */
public class KillIf {
    public static void main(String[] args) {

        // 1.三目运算符优化
        boolean condition = true;
        int price;
        if (condition) {
            price = 80;
        } else {
            price = 100;
        }
        // 优化后
        price = condition ? 80 : 100;





        // 2.枚举优化
        int index = 1;
        String goods = null;
        if (index == 1) {
            goods = "苹果";
        }
        if (index == 2) {
            goods = "橘子";
        }
        if (index == 3) {
            goods = "香蕉";
        }
        System.out.println("goods = " + goods);
        //优化后
        String goods1 = OrderEnum.index(index).getGoods();
        System.out.println("goods1 = " + goods1);





        // 3.策略+工厂优化
        String medalType = "guest";
        if (IMedalName.GUEST.equals(medalType)) {
            System.out.println("嘉宾勋章");
        } else if (IMedalName.VIP.equals(medalType)) {
            System.out.println("会员勋章");
        } else if (IMedalName.GUARD.equals(medalType)) {
            System.out.println("警卫勋章");
        }
        //优化后
        MedalServiceFactory.getMedalService(medalType).showMedal();

    }
}
